package com.wanlian.router.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.TextView;

import com.wanlian.router.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Hyu on 2018/9/18.
 * Email: fvaryu@163.com
 */
public class UpgradeDialog extends Dialog {

    @BindView(R.id.tv_log)
    TextView mLog;
    @BindView(R.id.tv_ignore)
    TextView tv_ignore;

    private boolean isForceUpdate;

    private String mUpgradeLog;
    private OnUpgradeClickListener mOnUpgradeClickListener;

    public void setOnUpgradeClickListener(OnUpgradeClickListener onUpgradeClickListener) {
        mOnUpgradeClickListener = onUpgradeClickListener;
    }

    public interface OnUpgradeClickListener {
        void onUpgradeClick(Dialog dialog, int which);
    }

    public UpgradeDialog(@NonNull Context context) {
        super(context, R.style.UpgradeDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.dialog_upgrade);
        ButterKnife.bind(this);

        setCancelable(false);
        setCanceledOnTouchOutside(false);
    }

    public void setUpgradeLog(String upgradeLog) {
        mUpgradeLog = upgradeLog;
    }

    public void setForceUpdate(boolean forceUpdate) {
        isForceUpdate = forceUpdate;
    }

    @Override
    protected void onStart() {
        super.onStart();
        mLog.setText(mUpgradeLog);
        if (isForceUpdate) {
            tv_ignore.setVisibility(View.GONE);
        }else {
            tv_ignore.setVisibility(View.VISIBLE);
        }
    }

    @OnClick(R.id.tv_ignore)
    void ignore() {
        if (mOnUpgradeClickListener != null) {
            mOnUpgradeClickListener.onUpgradeClick(this, 0);
        }
    }

    @OnClick(R.id.tv_next)
    void next() {
        if (mOnUpgradeClickListener != null) {
            mOnUpgradeClickListener.onUpgradeClick(this, 1);
        }
    }
}
